package com.sert.pet.manager;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.sert.pet.IPet;
import com.sert.pet.entity.Dog;

public class PetMap {
	
	private Map<Integer,IPet> mapList;
	
	public PetMap(){
		mapList=new HashMap<Integer,IPet>();
		
	}

	public Map<Integer, IPet> getMapList() {
		return mapList;
	}
	
	/**
	 * 修改
	 * @param name 要修改的名字
	 */
	public void update(String name){
		
		Set<Integer> keySet = mapList.keySet();
		Iterator<Integer> it = keySet.iterator();
		while(it.hasNext()){
			 int key = it.next();
			 IPet iPet = mapList.get(key);
			 if("哮天犬".equals(iPet.getName())){
//			 Dog dog=(Dog)iPet;
				 iPet.setColor("纯黑色");
				 iPet.setName("藏獒");
				 iPet.setAge(3);
				 break;
			 }
		}
	}
	
	/**
	 * 查找一个宠物
	 * @param name 名字
	 */
	public int findone(String name){
		int falg=-1;
		Set<Integer> keySet = mapList.keySet();
		Iterator<Integer> it = keySet.iterator();
		while(it.hasNext()){
			 int key = it.next();
			 IPet iPet = mapList.get(key);
			 if(name.equals(iPet.getName())){
				 falg=key;
				 break;
			 }
		}
		
		return falg;
		
	}

}
